const AuthService = require("../servers/UserInfo"); // 假设你的 AuthService 类在 authService.js 文件中

const verifyTokenMiddleware = async (req, res, next) => {
  const token = req.headers["authorization"];
  if (!token) {
    return res.status(401).send("No token provided");
  }
  try {
    const user = await AuthService.verifyToken(token);
    req.user = user; // 将用户信息附加到请求对象
    next();
  } catch (err) {
    res.status(401).send("Invalid token");
  }
};

module.exports = verifyTokenMiddleware;
